<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8" />
		<title>5.列表过滤_computed实现</title>
		<!-- 引入Vue -->
		<script type="text/javascript" src="../js/vue.js"></script>
	</head>
	<body>
		<!-- 准备好一个容器-->
		<div id="demo">
			<h2>人员列表</h2>
			<input type="text" v-model="keyword">
			<ul>
				<li v-for="p in persons2" :key="p.id">
					{{p.name}} - {{p.age}} - {{p.gender}}
				</li>
			</ul>
		</div>

		<script type="text/javascript">
			new Vue({
				el:'#demo',
				data:{
					keyword:'',
					persons:[
						{id:'87y872',name:'马冬梅',age:18,gender:'女'},
						{id:'87y657',name:'周冬雨',age:19,gender:'女'},
						{id:'87yt67',name:'周杰伦',age:20,gender:'男'},
						{id:'87y809',name:'温兆伦',age:34,gender:'男'}
					],
				},
				computed:{
					persons2(){
						let result = this.persons.filter((item)=>{
							return item.name.indexOf(this.keyword) !== -1
						})
						return result
					}
				}
			})
		</script>
	</body>
</html>